package com.tuanzi.loan.business.service.sms;

import com.tuanzi.loan.business.entity.sms.SmsCalculateTask;
import com.tuanzi.loan.business.entity.sms.SmsCalculateTaskStatus;
import com.tuanzi.loan.core.service.CommonService;
import com.tuanzi.loan.core.vo.PageSearcher;
import com.tuanzi.loan.vo.request.family.SmsCalculateTaskSearchRequest;
import com.tuanzi.loan.vo.request.family.SmsCondition;
import com.tuanzi.loan.vo.request.family.sms.ExternalSmsCalculateCondition;
import com.tuanzi.loan.vo.response.family.SmsCalculateTaskSearchResponse;
import org.springframework.data.domain.Page;

import java.util.Date;
import java.util.List;

/**
 * @author Ray 2017/12/12
 */
public interface SmsCalculateTaskService extends CommonService<SmsCalculateTask, Long> {

	/**
	 * 创建内部用户计算任务
	 * @param condition
	 * @return
	 */
	SmsCalculateTask addCalculateTask(SmsCondition condition);

	/**
	 * 创建外部用户计算任务
	 * @param condition
	 * @return
	 */
	SmsCalculateTask addExternalCalculateTask(ExternalSmsCalculateCondition condition);

	Page<SmsCalculateTaskSearchResponse> list(PageSearcher<SmsCalculateTaskSearchRequest> pageSearcher);

	void cancelTask(Long smsCalculateTaskId);

	void recalculate(Long smsCalculateTaskId);

	void activeTask(Long smsCalculateTaskId);

	Long countByStatus(SmsCalculateTaskStatus status);

	Long countByStatus(List<SmsCalculateTaskStatus> status);

	SmsCalculateTask findTopOneByStatus(SmsCalculateTaskStatus status);

	void updateStatusWithoutTransactional(SmsCalculateTask smsCalculateTask, SmsCalculateTaskStatus status);

	void calculateSmsCount(SmsCalculateTask calculateTask);

	Long estimateSmsCount(SmsCondition smsCondition);

	SmsCalculateTask findTopByStatusAndCalculateTimeBeforeOrderByCalculateTime(SmsCalculateTaskStatus status, Date date);

	SmsCalculateTask importPhones(String name, List<String> phones);

	List<SmsCalculateTask> findAllByIdsIn(List<Long> ids);
}
